
/**
 * Project Name:cats-web
 * File Name:UserController.java
 * Package Name:com.catsic.web.controllers
 * Date:2014年4月3日上午9:03:56
 * Copyright (c) 2014, oa.catsic.com All Rights Reserved.
 */
 
package com.catsic.web.controllers;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.catsic.base.annotation.Log;
import com.catsic.base.controller.BaseController;
import com.catsic.core.form.OrganForm;
import com.catsic.core.organ.service.OrganService;
import com.catsic.pub.constants.Constants;

/**
 * ClassName: OrganController
 * Description: 机构Controller
 * date: 2014年4月3日 上午9:03:56
 * author: yangyd
 */
@Controller
@RequestMapping("/organ")
public class OrganController extends BaseController{
	
	@Autowired
	private OrganService organService;
	
	/**
	 * create:创建
	 * @author yangyd
	 * @param form
	 * @return
	 */
	@RequestMapping(value = "/create" , method = RequestMethod.POST)
	@ResponseBody
	@Log(module = "机构管理", operation = "添加机构")
	public Map<String,Object> create(OrganForm form){
		form = organService.add(form);
		Map<String,Object> map = new HashMap<String,Object>();
		map.put(CONTENT,form);
		map.put(RESULT,RESULT_SUCCESS);
		return map;
	}
	
	/**
	 * update:更新
	 * @author yangyd
	 * @param form
	 * @return
	 */
	@RequestMapping(value = "/update" , method = RequestMethod.POST)
	@ResponseBody
	@Log(module = "机构管理", operation = "修改机构")
	public Map<String,Object> update(OrganForm form){
		form = organService.update(form);
		Map<String,Object> map = new HashMap<String,Object>();
		map.put(CONTENT,form);
		map.put(RESULT,RESULT_SUCCESS);
		return map;
	}

	/**
	 * delete:删除
	 * @author yangyd
	 * @param id
	 * @return 
	 */
	@RequestMapping(value = "/delete")
	@ResponseBody
	@Log(module = "机构管理", operation = "删除机构")
	public Map<String,Object> delete(String id){
		organService.delete(id);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put(RESULT,RESULT_SUCCESS);
		return map;
	}
	
	/**
	 * detail:详情
	 * @author yangyd
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/detail")
	@ResponseBody
	public Map<String,Object> detail(String id){
		Map<String,Object> map = new HashMap<String,Object>();
		map.put(CONTENT,organService.findOrganById(id));
		map.put(RESULT,RESULT_SUCCESS);
		return map;
	}
	
	/**
	 * code:编码
	 * @author yangyd
	 * @param 
	 * @return
	 */
	@RequestMapping(value = "/code")
	@ResponseBody
	@Log(module = "机构管理", operation = "编码机构")
	public Map<String,Object> code(){
		Map<String,Object> map = new HashMap<String,Object>();
		organService.code(Constants.部机构级别,Constants.部机构编码);
		map.put(RESULT,RESULT_SUCCESS);
		return map;
	}
	
	/**
	 * query:通过父机构ID查询子机构
	 * @author yangyd
	 * @param form
	 * @return
	 */
	@RequestMapping(value = "/query" , method = RequestMethod.GET)
	@ResponseBody
	public Map<String,Object> query(String id){
		List<OrganForm> form = organService.query(id);
		Map<String,Object> map = new HashMap<String,Object>();
		map.put(CONTENT,form);
		map.put(RESULT,RESULT_SUCCESS);
		return map;
	}
	
	/**
	 * findByPcode:通过父机构编码查询子机构
	 * @author yangyd
	 * @param form
	 * @return
	 */
	@RequestMapping(value = "/findByPcode" , method = RequestMethod.GET)
	@ResponseBody
	public Map<String,Object> findByPcode(String pcode){
		Map<String,Object> map = new HashMap<String,Object>();
		map.put(CONTENT,organService.listForm(organService.findByPcode(pcode)));
		map.put(RESULT,RESULT_SUCCESS);
		return map;
	}
}
